<html>
<head><meta charset="utf-8"><title>Debugging codegen · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html">Debugging codegen</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="229674288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229674288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229674288">(Mar 10 2021 at 14:57)</a>:</h4>
<p>I'm working on an experimental codegen change, and of course, I'm generating bad LLVM IR. I'd like to look at the generated IR, but the compiler (cargo rustc -- -C llvm-args=-print-after-all -C codegen-units=1) exits with an LLVM assertion failure before dumping the IR. Any hints for how I can see the bad IR I'm generating?</p>



<a name="229679627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229679627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229679627">(Mar 10 2021 at 15:23)</a>:</h4>
<p>Does -C no-prepopulate-passes work?</p>



<a name="229698571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229698571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229698571">(Mar 10 2021 at 16:40)</a>:</h4>
<p>I'll try it on my next debug cycle. Part of what's going on is I can't tell if the assertion occurs while generating the IR or while lowering it; there's no backtrace available and I don't know how to attach with a debugger to rustc invoked via cargo.</p>



<a name="229699479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229699479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229699479">(Mar 10 2021 at 16:45)</a>:</h4>
<p>separately, probably a basic Rust question: I have a function that takes <code>rust_type: Ty&lt;'_&gt;</code>. In that function's body, I pass <code>rust_type</code> as a parameter to another function, but I get this error: <code>`rust_type</code> escapes the associated function body here`</p>



<a name="229699567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229699567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229699567">(Mar 10 2021 at 16:45)</a>:</h4>
<p>it seems like passing it should be okay — it shouldn't outlive the function call</p>



<a name="229699653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229699653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229699653">(Mar 10 2021 at 16:46)</a>:</h4>
<p>so it's not clear to me what I'm doing wrong</p>



<a name="229700312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229700312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229700312">(Mar 10 2021 at 16:49)</a>:</h4>
<p>aha, needed to specify lifetime 'tcx rather than the anonymous lifetime. I wonder why the compiler couldn't figure it out.</p>



<a name="229705044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229705044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229705044">(Mar 10 2021 at 17:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="380247">Michael Coblenz</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Debugging.20codegen/near/229700312">said</a>:</p>
<blockquote>
<p>aha, needed to specify lifetime 'tcx rather than the anonymous lifetime. I wonder why the compiler couldn't figure it out.</p>
</blockquote>
<p>Because rustc doesn't look at the function body. Only at the function signature.</p>



<a name="229705893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229705893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229705893">(Mar 10 2021 at 17:19)</a>:</h4>
<p>There are a couple of things that could help:</p>
<ol>
<li>Build rustc with llvm with assertions enabled.</li>
</ol>



<a name="229705907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229705907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229705907">(Mar 10 2021 at 17:19)</a>:</h4>
<p>This should at least tell you what the assert was.</p>



<a name="229706040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229706040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229706040">(Mar 10 2021 at 17:20)</a>:</h4>
<p>You may have success inspecting a core dump rather than attaching to a live instance of rustc.</p>



<a name="229710046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229710046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229710046">(Mar 10 2021 at 17:43)</a>:</h4>
<p>You can pass -v to cargo to get the rustc invocation.</p>



<a name="229710780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229710780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229710780">(Mar 10 2021 at 17:47)</a>:</h4>
<p>yeah, but need to be careful to not accidentally attach to rustup's <code>rustc</code> wrapper if you go that way</p>



<a name="229712737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229712737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229712737">(Mar 10 2021 at 17:59)</a>:</h4>
<p>I do have llvm assertions enabled, so I do know what the assertion is. I just don't know what IR it's asserting on.</p>



<a name="229712969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229712969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229712969">(Mar 10 2021 at 18:00)</a>:</h4>
<p>And I have the rustc invocation, but it depends on setting some environment variables that cargo appears to set.</p>



<a name="229713298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229713298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229713298">(Mar 10 2021 at 18:02)</a>:</h4>
<p>How do I get a core dump for an assertion failure?</p>



<a name="229715871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229715871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229715871">(Mar 10 2021 at 18:19)</a>:</h4>
<p>Run <code>ulimit -c unlimited</code>. The core dump will be written to the location pointed to by <code>/proc/sys/kernel/core_pattern</code>. If the location starts with a <code>|</code>, the kernel actually pipes it to a program it starts as root.</p>



<a name="229716175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229716175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229716175">(Mar 10 2021 at 18:21)</a>:</h4>
<p>For example on my system <code>core_pattern</code> is <code>core</code>, so it will write to a file called <code>core</code> in the current directory. You can use something like <code>core%p</code> to write to a core file like <code>core100</code> when the pid of the process is 100. See <code>man 5 core</code> for more info.</p>



<a name="229716183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229716183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229716183">(Mar 10 2021 at 18:21)</a>:</h4>
<p><span class="user-mention" data-user-id="380247">@Michael Coblenz</span></p>



<a name="229717367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20codegen/near/229717367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20codegen.html#229717367">(Mar 10 2021 at 18:29)</a>:</h4>
<p>On many modern linux systems it might be written to systemd journal files, accessible via coredumpctl</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>